
<template>
  <div>
<h2>添加会员等级</h2>
<table class="table table-bordered">
<tbody>
  <tr>
    <td>会员等级名称</td>
    <td><input type="text" v-model="a.Name"/></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="添加" @click="add" /></td>
  </tr>
</tbody>
</table>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';
const router=useRouter();

let a=reactive({
  Name:''
})

const add=()=>{
  axios({
    method:'post',
    url:'/api/User/AddLevel',
    data:a
  })
  .then((res)=>{
    console.log(res);
    if(res.data==-1){
      alert("名称重复");
      return;
    }
    if(res.data>0){
      alert("添加成功");
      router.push('/')
    }
    else{
      alert("添加失败");
      return;
    }
  })
  .catch((err)=>{
    console.log(err);
  })
}






</script>

<style scoped>

</style>